/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.univalle.persistencia;

import co.edu.univalle.modelo.Clientes;
import co.edu.univalle.modelo.Empleados;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author valentina
 */
@Stateless
public class EmpleadoDAO implements IEmpleadoDAO {
    
    @PersistenceContext
    private EntityManager entityManager;


    @Override
    public void registrar(Empleados empleados) {
        
        try{
         entityManager.persist(empleados);
     }
     catch (RuntimeException e){
     throw e;
     
        }
    }

    @Override
    public void modificar(Empleados empleados) {
        
               try{
         entityManager.merge(empleados);
     }
     catch (RuntimeException e){
     throw e;
     }
      
   }
    
    

    @Override
    public void eliminar(Empleados empleados) {
       
         try{
         entityManager.remove(empleados);
     }
     catch (RuntimeException e){
     throw e;
         }
        
   }

    @Override
    public List<Empleados> consultar() {
     
                     try{
                String jpql = "SELECT c FROM Empleados c";
                Query query = entityManager.createQuery(jpql);
                return query.getResultList();
         
     }
     catch (RuntimeException e){
     throw e;
}
    }

    @Override
    public Empleados consultarPorIdEmpleado(Integer idempleado) {
        
               try{
                    return entityManager.find(Empleados.class, idempleado);
     }
                
     catch (RuntimeException e){
     throw e;
       
        }
    }

}
